/*
  ���潻��
*/

/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include <usart.h>

#include "../bsp/bsp_usart.h"
#include "../device/communicate.h"
#include "../device/hc05.h"
#include "../device/icm20602.h"
#include "../device/motor.h"
#include "FreeRTOS.h"
#include "usertask.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
#define MONITOR_SPEED 50u
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */

extern UartRx_t Rx;
extern UartRx_t Rx_openmv;
extern uint8_t openmv_buff[BUFF_DATA_T];
extern Euler_t angel;
extern Euler_t angel_2;
extern RawICM_t raw;
extern Cali_t cali;
extern Euler_t angel_raw;
extern float set_y;

static Interact_Coordinate_t coordinate;
Menu_t menu = {MENU_FIRST, MENU_FIRST, MENU_INIT, MENU_INIT,
               TASK_NONE,  TASK_NONE,  MENU_INIT};
// extern float set_y;
/* Private function --------------------------------------------------------- */
#include "stdio.h"
int fputc(int ch, FILE *f) {
  uint8_t temp[1] = {ch};
  HAL_UART_Transmit(&huart2, temp, 1, 0xFFFF);
  return 0;
}
/* Exported functions ------------------------------------------------------- */

void InteractTask(void *argument) {
  (void)argument;
  LCD_Init();
  uint32_t pretick;
  /* ICM校准 */
  while (ICM_Cali(&cali, &raw))
    ;
  cali.icm_init = 1;
  while (1) {
    /* 50ms */
    if (osKernelGetTickCount() - pretick > MONITOR_SPEED) {
      pretick = osKernelGetTickCount();
      if (LCD_IsScreenChange(menu)) {
        menu.main_menu_last = menu.main_menu;
        menu.sub_menu_last = menu.sub_menu;
        menu.key_showlast = menu.key_taskrun;
        menu.data_task1_last = menu.data_task1;
        menu.data_task2_last = menu.data_task2_last;
        LCD_TaskRun(&menu);
        LCD_Show(menu);
      }
      // HC05_CmdToBehavior(&Rx,rxhc_buff);
      Uart_PraseData(&Rx, openmv_buff, &coordinate);
      // Bsp_UartSendData(&Rx,rx_buff,Rx.rx_len);
      // printf("\r\nfb:%d,%d,%d,%d,%d,%d\n",raw.gyro.x,raw.gyro.y,raw.gyro.z,raw.acc.x,raw.acc.y,raw.acc.z);
      //            printf("\r\n fb:%f,%f,%f,%f,%f,%f,%f\n", angel_raw.pit,
      //            angel_raw.rol,angel_raw.yaw, angel.pit, angel.rol,
      //            angel.yaw,set_y);
    }
  }
}
